//获取应用实例
var app = getApp()
var util = require('../../utils/util.js');
var commonService = require('../../services/commonService.js');
var userGroupService = require('../../services/userGroupService.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    activityIng:[],
    activityIngPageSize:10,
    activityIngPageNum:1,
    activityIngHasMore:true,


    activityEnter:[],
    activityEnterPageSize: 10,
    activityEnterPageNum: 1,
    activityEnterHasMore:true,

    activityEnd:[],
    activityEndPageSize: 10,
    activityEndPageNum: 1,
    activityEndHasMore:true,

    currentStatus:2

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    that.GroupActivityListByStatus(that.data.currentStatus);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  GroupActivityListByStatus: function (status, append){
    var that = this;
    if (status == 2 && !that.data.activityEnterHasMore){
      return false;
    }
    if (status == 3 && !that.data.activityIngHasMore) {
      return false;
    }
    if (status == 4 && !that.data.activityEndHasMore) {
      return false;
    }
    if (status == 2){
      var pageSize = that.data.activityEnterPageSize;
      var pageNum = that.data.activityEnterPageNum;
    }
    if (status == 3) {
      var pageSize = that.data.activityIngPageSize;
      var pageNum = that.data.activityIngPageNum;
    }
    if (status == 4) {
      var pageSize = that.data.activityEndPageSize;
      var pageNum = that.data.activityEndPageNum;
    }
    userGroupService.GroupActivityListByStatus({
      user_id: app.globalData.sysUserInfo.userId,
      status: status,
      pageSize: pageSize,
      pageNum: pageNum,
      success:function(res){
        var data=[];
        if(append){
          if(status == 2){
            data = that.data.activityEnter
          }
          if (status == 3) {
            data = that.data.activityIng
          }
          if (status == 4) {
            data = that.data.activityEnd
          }
        }

        for(var i =0; i<res.list.length;i++){
          res.list[i].start_time = util.makeDateTimeToPretty(new Date(res.list[i].active_time_start.replace(/-/g, "/")), true);
          res.list[i].end_time = util.makeDateTimeToPretty(new Date(res.list[i].active_time_end.replace(/-/g, "/")), true);
          data.push(res.list[i]);
        }
        if (status == 2) {
          that.setData({
            activityEnter:data,
            activityEnterPageNum: that.data.activityEnterPageNum+1,
            activityIngHasMore: res.hasMore
          })
        }
        if (status == 3) {
          that.setData({
            activityIng: data,
            activityIngPageNum: that.data.activityIngPageNum + 1,
            activityIngHasMore: res.hasMore
          })
        }
        if (status == 4) {
          that.setData({
            activityEnd: data,
            activityEndPageNum: that.data.activityIngPageNum + 1,
            activityEndHasMore: res.hasMore
          })
        }
      }
    })
  },
  changeStatus:function(e){
    var that = this;
    var status = e.currentTarget.dataset.status;
    that.setData({
      currentStatus: status
    })
    that.GroupActivityListByStatus(status);
  },
  releaseActivity:function(e){
    var that = this;
    that.GroupActivityListByStatus(that.data.currentStatus,1);
  },
  clickDetails:function(e){
    var id = e.currentTarget.dataset.id;
    var group_id = e.currentTarget.dataset.gid;
    wx.navigateTo({
      url: './myActivityDetail?id=' + id + '&group_id=' + group_id,
    })
  }
})